home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb.new / gdb-4.0 / include / a.out.gnu.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-24  |  9.2 KB  |  315 lines

  1. #ifndef __A_OUT_GNU_H__
  2. #define __A_OUT_GNU_H__
  3.  
  4. #include "reloc.h"
  5.  
  6. #define __GNU_EXEC_MACROS__
  7.  
  8. #ifndef __STRUCT_EXEC_OVERRIDE__
  9.  
  10. /* This is the layout on disk of a Unix V7, Berkeley, SunOS, Vax Ultrix
  11.    "struct exec".  Don't assume that on this machine, the "struct exec"
  12.    will lay out the same sizes or alignments.  */
  13.  
  14. struct exec_bytes {
  15.   unsigned char a_info[4];
  16.   unsigned char a_text[4];
  17.   unsigned char a_data[4];
  18.   unsigned char a_bss[4];
  19.   unsigned char a_syms[4];
  20.   unsigned char a_entry[4];
  21.   unsigned char a_trsize[4];
  22.   unsigned char a_drsize[4];
  23. };
  24.  
  25. /* How big the "struct exec" is on disk */
  26. #define    EXEC_BYTES_SIZE    (8 * 4)
  27.  
  28. /* This is the layout in memory of a "struct exec" while we process it.  */
  29.  
  30. struct exec
  31. {
  32.   unsigned long a_info;        /* Use macros N_MAGIC, etc for access */
  33.   unsigned a_text;        /* length of text, in bytes */
  34.   unsigned a_data;        /* length of data, in bytes */
  35.   unsigned a_bss;        /* length of uninitialized data area for file, in bytes */
  36.   unsigned a_syms;        /* length of symbol table data in file, in bytes */
  37.   unsigned a_entry;        /* start address */
  38.   unsigned a_trsize;        /* length of relocation info for text, in bytes */
  39.   unsigned a_drsize;        /* length of relocation info for data, in bytes */
  40. };
  41.  
  42. #endif /* __STRUCT_EXEC_OVERRIDE__ */
  43.  
  44. /* these go in the N_MACHTYPE field */
  45. /* These symbols could be defined by code from Suns...punt 'em */
  46. #undef M_UNKNOWN
  47. #undef M_68010
  48. #undef M_68020
  49. #undef M_SPARC
  50. enum machine_type {
  51.   M_UNKNOWN = 0,
  52.   M_68010 = 1,
  53.   M_68020 = 2,
  54.   M_SPARC = 3,
  55.   /* skip a bunch so we don't run into any of sun's numbers */
  56.   M_386 = 100,
  57.   M_29K = 101,
  58.   /* HP/BSD formats */
  59.   M_HP200 = 200,    /* hp200 (68010) BSD binary */
  60.   M_HP300 = 300,    /* hp300 (68020+68881) BSD binary */
  61.   M_HPUX23 = 0x020C,    /* hp200/300 HPUX binary */
  62. };
  63.  
  64. #define N_MAGIC(exec) ((exec).a_info & 0xffff)
  65. #define N_MACHTYPE(exec) ((enum machine_type)(((exec).a_info >> 16) & 0xff))
  66. #define N_FLAGS(exec) (((exec).a_info >> 24) & 0xff)
  67. #define N_SET_INFO(exec, magic, type, flags) \
  68.     ((exec).a_info = ((magic) & 0xffff) \
  69.      | (((int)(type) & 0xff) << 16) \
  70.      | (((flags) & 0xff) << 24))
  71. #define N_SET_MAGIC(exec, magic) \
  72.     ((exec).a_info = (((exec).a_info & 0xffff0000) | ((magic) & 0xffff)))
  73.  
  74. #define N_SET_MACHTYPE(exec, machtype) \
  75.     ((exec).a_info = \
  76.      ((exec).a_info&0xff00ffff) | ((((int)(machtype))&0xff) << 16))
  77.  
  78. #define N_SET_FLAGS(exec, flags) \
  79.     ((exec).a_info = \
  80.      ((exec).a_info&0x00ffffff) | (((flags) & 0xff) << 24))
  81.  
  82. /* Code indicating object file or impure executable.  */
  83. #define OMAGIC 0407
  84. /* Code indicating pure executable.  */
  85. #define NMAGIC 0410
  86. /* Code indicating demand-paged executable.  */
  87. #define ZMAGIC 0413
  88.  
  89. /* Virtual Address of text segment from the a.out file.  For OMAGIC,
  90.    (almost always "unlinked .o's" these days), should be zero.
  91.    For linked files, should reflect reality if we know it.  */
  92.  
  93. #ifndef N_TXTADDR
  94. #define N_TXTADDR(x)    (N_MAGIC(x)==OMAGIC? 0 : TEXT_START_ADDR)
  95. #endif
  96.  
  97. #ifndef N_BADMAG
  98. #define N_BADMAG(x)      (N_MAGIC(x) != OMAGIC        \
  99.             && N_MAGIC(x) != NMAGIC        \
  100.               && N_MAGIC(x) != ZMAGIC)
  101. #endif
  102.  
  103. /* By default, segment size is constant.  But on some machines, it can
  104.    be a function of the a.out header (e.g. machine type).  */
  105. #ifndef    N_SEGSIZE
  106. #define    N_SEGSIZE(x)    SEGMENT_SIZE
  107. #endif
  108.  
  109. /* This complexity is for encapsulated COFF support */
  110. #ifndef _N_HDROFF
  111. #define _N_HDROFF(x)    (N_SEGSIZE(x) - sizeof (struct exec))
  112. #endif
  113.  
  114. #ifndef N_TXTOFF
  115. #define N_TXTOFF(x)    (N_MAGIC(x) == ZMAGIC ?    \
  116.                 _N_HDROFF((x)) + sizeof (struct exec) :    \
  117.                 sizeof (struct exec))
  118. #endif
  119.  
  120.  
  121. #ifndef N_DATOFF
  122. #define N_DATOFF(x)    ( N_TXTOFF(x) + (x).a_text )
  123. #endif
  124.  
  125. #ifndef N_TRELOFF
  126. #define N_TRELOFF(x)    ( N_DATOFF(x) + (x).a_data )
  127. #endif
  128.  
  129. #ifndef N_DRELOFF
  130. #define N_DRELOFF(x)    ( N_TRELOFF(x) + (x).a_trsize )
  131. #endif
  132.  
  133. #ifndef N_SYMOFF
  134. #define N_SYMOFF(x)    ( N_DRELOFF(x) + (x).a_drsize )
  135. #endif
  136.  
  137. #ifndef N_STROFF
  138. #define N_STROFF(x)    ( N_SYMOFF(x) + (x).a_syms )
  139. #endif
  140.  
  141. /* Address of text segment in memory after it is loaded.  */
  142. #ifndef N_TXTADDR
  143. #define    N_TXTADDR(x)    0
  144. #endif
  145.  
  146. #ifndef N_DATADDR
  147. #define N_DATADDR(x) \
  148.     (N_MAGIC(x)==OMAGIC? (N_TXTADDR(x)+(x).a_text) \
  149.      :  (N_SEGSIZE(x) + ((N_TXTADDR(x)+(x).a_text-1) & ~(N_SEGSIZE(x)-1))))
  150. #endif
  151.  
  152. /* Address of bss segment in memory after it is loaded.  */
  153. #define N_BSSADDR(x) (N_DATADDR(x) + (x).a_data)
  154.  
  155. struct nlist {
  156.   union {
  157.     char *n_name;
  158.     struct nlist *n_next;
  159.     long n_strx;
  160.   } n_un;
  161.   unsigned char n_type;
  162.   char n_other;
  163.   short n_desc;
  164.   unsigned long n_value;
  165. };
  166.  
  167. #define N_UNDF 0
  168. #define N_ABS 2
  169. #define N_TEXT 4
  170. #define N_DATA 6
  171. #define N_BSS 8
  172. #define N_FN 0x1e
  173.  
  174. #define N_EXT 1
  175. #define N_TYPE 036
  176. #define N_STAB 0340
  177.  
  178. /* The following type indicates the definition of a symbol as being
  179.    an indirect reference to another symbol.  The other symbol
  180.    appears as an undefined reference, immediately following this symbol.
  181.  
  182.    Indirection is asymmetrical.  The other symbol's value will be used
  183.    to satisfy requests for the indirect symbol, but not vice versa.
  184.    If the other symbol does not have a definition, libraries will
  185.    be searched to find a definition.  */
  186.  
  187. #define N_INDR 0xa
  188.  
  189. /* The following symbols refer to set elements.
  190.    All the N_SET[ATDB] symbols with the same name form one set.
  191.    Space is allocated for the set in the text section, and each set
  192.    element's value is stored into one word of the space.
  193.    The first word of the space is the length of the set (number of elements).
  194.  
  195.    The address of the set is made into an N_SETV symbol
  196.    whose name is the same as the name of the set.
  197.    This symbol acts like a N_DATA global symbol
  198.    in that it can satisfy undefined external references.  */
  199.  
  200. /* These appear as input to LD, in a .o file.  */
  201. #define    N_SETA    0x14        /* Absolute set element symbol */
  202. #define    N_SETT    0x16        /* Text set element symbol */
  203. #define    N_SETD    0x18        /* Data set element symbol */
  204. #define    N_SETB    0x1A        /* Bss set element symbol */
  205.  
  206. /* This is output from LD.  */
  207. #define N_SETV    0x1C        /* Pointer to set vector in data area.  */
  208.  
  209. /* This structure describes a single relocation to be performed.
  210.    The text-relocation section of the file is a vector of these structures,
  211.    all of which apply to the text section.
  212.    Likewise, the data-relocation section applies to the data section.  */
  213.  
  214. /* The following enum and struct were borrowed from SunOS's
  215.    /usr/include/sun4/a.out.h  and extended to handle
  216.    other machines.  It is currently used on SPARC and AMD 29000.
  217.  
  218.    reloc_ext_bytes is how it looks on disk.  reloc_info_extended is
  219.    how we might process it on a native host.  */
  220.  
  221. struct reloc_ext_bytes {
  222.   unsigned char    r_address[4];
  223.   unsigned char r_index[3];
  224.   unsigned char r_bits[1];
  225.   unsigned char r_addend[4];
  226. };
  227.  
  228. #define    RELOC_EXT_BITS_EXTERN_BIG    0x80
  229. #define    RELOC_EXT_BITS_EXTERN_LITTLE    0x01
  230.  
  231. #define    RELOC_EXT_BITS_TYPE_BIG        0x1F
  232. #define    RELOC_EXT_BITS_TYPE_SH_BIG    0
  233. #define    RELOC_EXT_BITS_TYPE_LITTLE    0xF8
  234. #define    RELOC_EXT_BITS_TYPE_SH_LITTLE    3
  235.  
  236. #define    RELOC_EXT_SIZE    12        /* Bytes per relocation entry */
  237.  
  238. struct reloc_info_extended
  239. {
  240.   unsigned long r_address;
  241.   unsigned int  r_index:24;
  242. # define    r_symbolnum  r_index
  243.   unsigned    r_extern:1;
  244.   unsigned    :2;
  245.   enum reloc_type r_type:5;
  246.   long int    r_addend;
  247. };
  248.  
  249. /* The standard, old-fashioned, Berkeley compatible relocation struct */
  250.  
  251. struct reloc_std_bytes {
  252.   unsigned char    r_address[4];
  253.   unsigned char r_index[3];
  254.   unsigned char r_bits[1];
  255. };
  256.  
  257. #define    RELOC_STD_BITS_PCREL_BIG    0x80
  258. #define    RELOC_STD_BITS_PCREL_LITTLE    0x01
  259.  
  260. #define    RELOC_STD_BITS_LENGTH_BIG    0x60
  261. #define    RELOC_STD_BITS_LENGTH_SH_BIG    5    /* To shift to units place */
  262. #define    RELOC_STD_BITS_LENGTH_LITTLE    0x06
  263. #define    RELOC_STD_BITS_LENGTH_SH_LITTLE    1
  264.  
  265. #define    RELOC_STD_BITS_EXTERN_BIG    0x10
  266. #define    RELOC_STD_BITS_EXTERN_LITTLE    0x08
  267.  
  268. #define    RELOC_STD_BITS_BASEREL_BIG    0x08
  269. #define    RELOC_STD_BITS_BASEREL_LITTLE    0x08
  270.  
  271. #define    RELOC_STD_BITS_JMPTABLE_BIG    0x04
  272. #define    RELOC_STD_BITS_JMPTABLE_LITTLE    0x04
  273.  
  274. #define    RELOC_STD_BITS_RELATIVE_BIG    0x02
  275. #define    RELOC_STD_BITS_RELATIVE_LITTLE    0x02
  276.  
  277. #define    RELOC_STD_SIZE    8        /* Bytes per relocation entry */
  278.  
  279. struct relocation_info
  280. {
  281.   /* Address (within segment) to be relocated.  */
  282.   int r_address;
  283.   /* The meaning of r_symbolnum depends on r_extern.  */
  284.   unsigned int r_symbolnum:24;
  285.   /* Nonzero means value is a pc-relative offset
  286.      and it should be relocated for changes in its own address
  287.      as well as for changes in the symbol or section specified.  */
  288.   unsigned int r_pcrel:1;
  289.   /* Length (as exponent of 2) of the field to be relocated.
  290.      Thus, a value of 2 indicates 1<<2 bytes.  */
  291.   unsigned int r_length:2;
  292.   /* 1 => relocate with value of symbol.
  293.           r_symbolnum is the index of the symbol
  294.       in file's the symbol table.
  295.      0 => relocate with the address of a segment.
  296.           r_symbolnum is N_TEXT, N_DATA, N_BSS or N_ABS
  297.       (the N_EXT bit may be set also, but signifies nothing).  */
  298.   unsigned int r_extern:1;
  299.   /* The next three bits are for SunOS shared libraries, and seem to
  300.      be undocumented.  */
  301.   unsigned int r_baserel:1;    /* Linkage table relative */
  302.   unsigned int r_jmptable:1;    /* pc-relative to jump table */
  303.  
  304. #ifdef TC_NS32K
  305. #define r_bsr    r_baserel
  306. #define r_disp    r_jmptable
  307. #endif /* TC_NS32K */
  308.  
  309.   unsigned int r_relative:1;    /* "relative relocation" */
  310.   /* unused */
  311.   unsigned int r_pad:1;        /* Padding -- set to zero */
  312. };
  313.  
  314. #endif /* __A_OUT_GNU_H__ */
  315.